const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
var app = getApp();
Page({
  data: {
    todayNum:0,
    carNum:0,
    coachNum:0,
    detail: {},
    page: 1,
    limit: 30,
    totalPages: 1,
    endFlag: false,
    loadingFlag: false,
    flag: 0,
    navbar_bgcolor: wx.getStorageSync('navbar_bgcolor'),
    activeCategoryId: 1,
    schoolId: 0,
    placeList: [],  //场地信息
    classTypeList: [], //班型信息
    coachList: [],  //教练信息
    licensePlate: [], //车牌信息
  },

  onLoad: function (options) {
    this.setData({
      schoolId: options.id
    });
    this.getSchoolDetail();
    this.getlicensePlate();
  },

  getSchoolDetail: function () {
    var hasLogin = wx.getStorageSync("app.globalData.hasLogin");
    if (!hasLogin) {//已经授权了
      return;
    }

    wx.showLoading({
      title: '加载中',
    });

    setTimeout(function () {
      wx.hideLoading()
    }, 2000);

    let that = this;
    //获取用户信息
    var userid = wx.getStorageSync("userid");
    util.request(api.mySchoolDetailUrl, {
      id: userid
    }).then(function (res) {
      if (res.errno === 0) {
        //console.log(res.data);
        //console.log(res.data.classTypeList);
        that.setData({
          detail: res.data.detail,
          placeList: res.data.placeList,
          classTypeList: res.data.classTypeList,
          coachList: res.data.coachList,
          todayNum :res.data.num,
          coachNum :res.data.coachNum,
          carNum :res.data.carNum
        });
      }

      wx.hideLoading();
    });
  },
  //获取教练车信息
  getlicensePlate: function () {
    let that = this;
    util.request(api.SchoollicensePlate, {
      schoolId: that.data.schoolId,
      page: that.data.page,
      limit: that.data.limit
    }).then(function (res) {
      that.setData({
        licensePlate: that.data.licensePlate.concat(res.data.list),
        totalPages: res.data.pages
      })
    });
    wx.hideLoading();
  },

  tabClick: function (e) {
    this.setData({
      //activeIndex: e.currentTarget.id
      activeCategoryId: e.currentTarget.id
    });
  },

  tobm: function (e) {
    /*var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name
    wx.navigateTo({
      url: '/pages/signup/add?jiaxiaoId=' + id + "&jiaxiaoName=" + name
    })*/
    wx.navigateTo({
      url: '/pages/signupV3/selectCarModel',
    })
  },

  onShareAppMessage: function (res) {
  },
  onPullDownRefresh: function () {
  }
  ,
  //地图跳转
  fnMap: function (e) {
    var location = e.currentTarget.dataset.location;
  },
  toNav: function (e) {
    var latitude=this.data.detail.latitude;
    var longitude=this.data.detail.longitude;
    var name=this.data.detail.name;
    var address=this.data.detail.address;
    wx.openLocation({//?使用微信内置地图查看位置。
      latitude: Number(latitude),//要去地点的纬度
      longitude: Number(longitude),///要去地点的经度-地址
      name: name,//
      address: address
    })
  }
})